import time

from selenium.webdriver.common.by import By

from common.Utils import forum


class postDetail:
    # url = ""
    driver = ""

    def __init__(self):
        self.url = "http://127.0.0.1:58080/index.html"
        self.driver = forum.driver
        self.driver.get(self.url)

    # 检查页面元素
    def PostCheck(self):
        # 选择C++板块的帖子进行测试
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(3) > a").click()

        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong").click()
        # 帖子详情页面的元素进行查找
        # 发布人
        self.driver.find_element(By.CSS_SELECTOR, "#article_details_author_name")
        # 发布时间
        self.driver.find_element(By.CSS_SELECTOR, "#details_article_createTime")
        # 帖子的标题
        self.driver.find_element(By.CSS_SELECTOR, "#details_article_title")
        time.sleep(1)
        # 评论区列表
        text = self.driver.find_element(By.CSS_SELECTOR, "#details_article_reply_content_2").text
        print(text)

        # 评论输入框
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#article_details_reply > div.CodeMirror.cm-s-default.CodeMirror-wrap > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div.CodeMirror-activeline > pre")

        # 评论发布按钮
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_article_reply")
        # 点赞按钮
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_like_count")

    # 功能测试
    def PostFunCheck(self):
        # 选择C++板块的帖子进行测试
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li:nth-child(3) > a").click()

        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong").click()
        # 测试用例一：编辑一个评论进行发布
        # 发送一个评论看是否在列表中正常显示
        #找到评论编辑框进行输入
        self.driver.find_element(By.CSS_SELECTOR,"#article_details_reply > div.editormd-toolbar > div > ul > li:nth-child(7) > a").click()
        #找到回复按钮点击进行回复
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_article_reply").click()


        # 二、对点赞功能进行测试
        # 寻找点赞按钮并点击
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_like_count").click()
        text2 = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right").text
        print(text2)

        time.sleep(1)
        # 进行截图验证
        forum.GetScreenShot()

        # 三、任意点击一个帖子给帖子的作者发私信
        self.driver.find_element(By.CSS_SELECTOR, "#btn_details_send_message").click()
        time.sleep(2)
        # 输入信息
        self.driver.find_element(By.CSS_SELECTOR, "#index_message_receive_content").send_keys("111111111")
        time.sleep(1)
        # 点击发送
        self.driver.find_element(By.CSS_SELECTOR, "#btn_index_send_message").click()

        time.sleep(2)
